<?php include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/conn_db.php");?>
<?php include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/Util.php");?>
<?php //DB Open

	$result = null;
	$db = new MyDB ( false );
	$db->err_report = true;

?>
<?php

	$util = new Util();

	$initial = $_POST['init'];

	//초성 List where

	$in[0] = "";
	$in[1] = "and ( category_name rlike '^(ㄱ)' or (category_name >= '가'  and category_name < '나') )";
	$in[2] = "and ( category_name rlike '^(ㄴ)' or (category_name >= '나'  and category_name < '다') )";
	$in[3] = "and ( category_name rlike '^(ㄷ)' or (category_name >= '다'  and category_name < '라') )";
	$in[4] = "and ( category_name rlike '^(ㄹ)' or (category_name >= '라'  and category_name < '마') )";
	$in[5] = "and ( category_name rlike '^(ㅁ)' or (category_name >= '마'  and category_name < '바') )";
	$in[6] = "and ( category_name rlike '^(ㅂ)' or (category_name >= '바'  and category_name < '사') )";
	$in[7] = "and ( category_name rlike '^(ㅅ)' or (category_name >= '사'  and category_name < '아') )";
	$in[8] = "and ( category_name rlike '^(ㅇ)' or (category_name >= '아'  and category_name < '자') )";
	$in[9] = "and ( category_name rlike '^(ㅈ)' or (category_name >= '자'  and category_name < '차') )";
	$in[10] = "and ( category_name rlike '^(ㅊ)' or (category_name >= '차'  and category_name < '카') )";
	$in[11] = "and ( category_name rlike '^(ㅋ)' or (category_name >= '카'  and category_name < '타') )";
	$in[12] = "and ( category_name rlike '^(ㅌ)' or (category_name >= '타'  and category_name < '파') )";
	$in[13] = "and ( category_name rlike '^(ㅍ)' or (category_name >= '파'  and category_name < '하') )";
	$in[14] = "and ( category_name rlike '^(ㅎ)' or category_name >= '하' )";

	$where = "where category_parent=1 ".$in[$initial]." order by category_name asc";

	$sql = " SELECT category_lft, category_rgt,category_hanja, category_name FROM tb_category ".$where;
	$db->query ( $sql );
	$query = $db->result;
	$total = mysql_num_rows ($query);

	$i=0;

?>
<?php //DB Close

	$db->close ();

?>
<table width="432" border="0" cellspacing="0" cellpadding="0">
  <?php if($total>0):?>
	<?php while($row = mysql_fetch_object($query)):?>
	  <?php if($i%10==0):?>
		<tr>
		  <td style="padding-bottom:7px;"><table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr>
	  <?php endif;?>
			<td style="padding-right:7px;"><table width="84" height="32" border="0" cellpadding="0" cellspacing="0">
				<tr>
				  <td align="center" background="img/surn/cont_img04.jpg" id="bg<?=$i?>" class="text03"><a href="#" id="a_<?=$i?>" class="su1" onclick="step3(<?php echo $row->category_lft;?>,<?php echo $row->category_rgt;?>,<?=$i?>,<?=$total?>); return false;"><strong><?php echo $row->category_name;?>(<?php echo $row->category_hanja;?>)</strong></a></td>
				</tr>
			</table></td>
	  <?php if($i%10==9):?>
			  </tr>
			</table></td>
		  </tr>
	  <?php endif;?>
	  <?php $i++;?>
	<?php endwhile;?>
  <?php endif;?>
  <?php if($i%10!=0):?>
	<?php for($j=0;$j<10-($i%10);$j++):?>
		<td style="padding-right:7px;" width="84">&nbsp;</td>
	<?php endfor;?>
		  </tr>
	  </table></td>
	</tr>
  <?php endif?>
</table>